import os
from captcha.image import ImageCaptcha
import random

list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]


def random_choice(len):
    array = []
    for _ in range(len):
        array.append(str(random.choice(list)))
    return "".join(array)


def create_captcha(captcha_content, file_dir):
    image = ImageCaptcha()
    image.generate_image(captcha_content)
    file_path = os.path.join(file_dir, "%s.png" % captcha_content)
    image.write(captcha_content, file_path)


if __name__ == '__main__':
    dir = 'F:\Idea workspace\\tensorflow-learning\data\sample\captcha'
    for i in range(10000):
        content = random_choice(4)
        create_captcha(content, dir)
        print(i)
